const MyPromise = require('./MyPromise');

let myPromise = new MyPromise((resolve, reject) => {
  // setTimeout(() => {
  //   resolve('success')
  //   // reject('fail')
  // }, 2000);

  // resolve('success')
  reject('fail')
})

myPromise.then(res => {
  console.log('-then res-', res)
}, err => {
  console.log('-then err-', err)
}).catch(err => {
  console.log('-catch err-', err)
})

myPromise.then().then().then(res => {
  console.log('-then-3 res-', res)
}, err => {
  console.log('-then-3 err-', err)
})

function p1() {
  return new MyPromise((resolve, reject) => {
    setTimeout(() => {
      // resolve('p1 success')
      reject('p1 fail')
    }, 2000);
  })
}
function p2() {
  return new MyPromise((resolve, reject) => {
    resolve('p2 success')
    // reject('p2 fail')
  })
}

MyPromise.all(['a', p1(), p2(), 'b']).then(res => {
  console.log('-MyPromise.all res-', res)
}, err => {
  console.log('-MyPromise.all err-', err)
})

// myPromise.then(res => {
//   console.log('-myPromise-1 res-', res)
//   return '-myPromise-1 then'
// }, err => {
//   console.log('-myPromise-1 err-', err)
// }).then(res => {
//   console.log('-myPromise-2 res-', res)
// }, err => {
//   console.log('-myPromise-2 err-', err)
// })

// let p1 = myPromise.then(res => {
//   console.log('-myPromise-1 res-', res)
//   return p1
// })

// p1.then(() => {}, err => {
//   console.log(err.message)
// })